package com.msb.servicemap.remote;

import com.msb.internalcommon.constant.AmapConfigConstants;
import com.msb.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: WuWen
 * @Date: 2023/8/21 - 08 - 21 - 14:45
 * @Description: com.msb.servicemap.remote
 * @version: 1.0
 */
@Service
public class MapDicDistrictClient {
    @Value("${amap.key}")
    String key;

    @Autowired
    RestTemplate restTemplate;

    public String initDistrict(String keywords) {

        // 组装URL
        // https://restapi.amap.com/v3/config/district?keywords=北京&subdistrict=2&key=<用户的key>

        StringBuilder districtURL = new StringBuilder();
        districtURL.append(AmapConfigConstants.DISTRICT_URL)
                .append("?")
                .append("keywords=").append(keywords)
                .append("&")
                .append("subdistrict=3")
                .append("&")
                .append("key=").append(key);
        String url = districtURL.toString();

        // 调用接口
        ResponseEntity<String> districtEntity = restTemplate.getForEntity(url, String.class);


        return districtEntity.getBody();
    }
}
